package dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class BookDao {

    @Autowired
    JdbcTemplate template;

    /*
    * 减去某一个用户余额
    * */
    public void updateBalance(String userName,int price){
        String sql = "update account set balance=balance-? where username=?";
        template.update(sql,price,userName);
    }

    /*
    * 获取某本图书的价格
    * */
    public int getPrice(String isbn){
        String sql = "select price from book where isbn=?";
        return template.queryForObject(sql,Integer.class,isbn);
    }

    /*
    * 减去某本书的库存
    * */
    public void updateStock(String isbn){
        String sql = "update book_stock set stock=stock-1 where isbn=?";
        template.update(sql,isbn);
    }

}
